from flask import Flask, request, jsonify

app = Flask(__name__)


@app.route('/', methods=['GET'])
def home():
    return "This is a GET request"


@app.route('/post_data', methods=['POST'])
def post_data():
    # 下面这句的意思：
    # 1. request.get_json()获取请求的json数据，为key-value格式的字典
    # 2. get字典的key:"data"
    # 以下等价于两句
    # request_data = request.get_json()
    # data = request_data.get("data")
    data = request.get_json().get("data")

    # 省略中间数据处理的流程

    # 以json形式返回给客户端
    return jsonify(data)


if __name__ == '__main__':
    app.run(debug=True)
